﻿using System.Threading.Tasks;
using kemocard.Scripts.Buff;
using kemocard.Scripts.Common;

namespace kemocard.Scripts.Card.Scripts;

public class BaseBuffCard(string buffId) : BaseCardScript
{
    public sealed override Task UseCard(BaseBattleCard parent)
    {
        var buff = StaticUtil.NewBuffOrNullById(buffId, parent.User);
        if (buff == null) return Task.CompletedTask;
        AfterSetBuff(buff, parent);
        // if (parent.Tags.Contains(Tag.SELF))
        // {
        //     parent.User.AddBuff(buff);
        // }
        // else if (parent.Tags.Contains(Tag.AT))
        // {
        //     foreach (var battleCharacter in Mod.Teammates)
        //     {
        //         battleCharacter.AddBuff(buff);
        //     }
        // }
        // else if (parent.Tags.Contains(Tag.AE))
        // {
        //     foreach (var battleEnemy in Mod.Enemies)
        //     {
        //         battleEnemy.AddBuff(buff);
        //     }
        // }
        // else if (parent.Tags.Contains(Tag.SE) || parent.Tags.Contains(Tag.ST))
        // {
        //     foreach (var basePawn in parent.Target)
        //     {
        //         basePawn.AddBuff(buff);
        //     }
        // }
        foreach (var target in parent.Target)
        {
            var cloneBuff = (BaseBuff)buff.Clone();
            target.AddBuff(cloneBuff);
        }

        AfterAddBuff(parent);
        
        return Task.CompletedTask;
    }

    /// <summary>
    /// buff创建完成后
    /// </summary>
    /// <param name="buff">buff实例</param>
    /// <param name="parent">创建者</param>
    protected virtual void AfterSetBuff(BaseBuff buff, BaseBattleCard parent)
    {
    }

    /// <summary>
    /// buff添加完后
    /// </summary>
    /// <param name="parent">创建者</param>
    protected virtual void AfterAddBuff(BaseBattleCard parent)
    {
    }
}